package com.xiaohe66.web.domain.love.service;

import com.xiaohe66.web.domain.love.agg.LeaveWord;
import com.xiaohe66.web.domain.love.repository.LoverRepository;
import com.xiaohe66.web.domain.love.repository.LeaveWordRepository;
import com.xiaohe66.web.domain.love.value.LoverId;
import com.xiaohe66.web.domain.love.value.LeaveWordId;
import com.xiaohe66.web.domain.sys.sec.service.SecurityService;
import com.xiaohe66.common.value.Paging;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author xiaohe
 * @since 2021.12.07 11:50
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class LeaveWordService {

    private final LeaveWordRepository leaveWordRepository;
    private final LoverRepository loverRepository;
    private final SecurityService securityService;


    public void save(LeaveWord message) {

        leaveWordRepository.save(message);
    }

    public void remove(LeaveWordId id) {

        LeaveWord leaveWord = leaveWordRepository.getById(id);

        securityService.checkCurrentAccountPermission(leaveWord.getCreateId());

        leaveWordRepository.removeById(id);
    }

    public List<LeaveWord> listDesc(LoverId loverId, Paging paging) {

        return leaveWordRepository.listDesc(loverId, paging);
    }

}
